// pages/tabbar/native/index.js
var basePage = require('../../../common/BasePage')
Page({
    behaviors: [basePage],
    /**
     * 页面的初始数据
     */
    data: {
        navInfo: getApp().globalData.navInfo,
        swiperCurrent: 0,
        bannerArr: [],
        wh_id: 1,
        lat: "",
        lng: "",
        address: {}, //位置
        whInfo: null, //仓库信息
        glWhInfo: null, //关联仓库
        is_have_city: 0, //1有城市仓
        is_have_district: 0, //1有区级仓
        showArea: false,
        addrs: [],
        reqData: {},
        adrr: "",
        showtype:false,
        actions: [{
                name: '城市仓',
                type: 2
            },
            {
                name: '区县仓',
                type: 1
            }
        ],
        typeInfo: {},
        article_content: "",
        turnoverList: [],
        sales: 0,
        analysisList: [],
        activeIndex: 0,
        phone: "",
        name: "",
        mobile: "",
        remark: "",
        activeArr: [
            // {
            //     title:"秒杀",
            //     subtitle:"性价比高",
            //     url:""
            // },
            {
                title: "活动",
                subtitle: "今日活动",
                url: ""
            },
            {
                title: "推荐",
                subtitle: "优品严选",
                url: ""
            },
            {
                title: "秒杀",
                subtitle: "性价比高",
                url: ""
            },
            // {
            //     title:"活动",
            //     subtitle:"今日活动",
            //     url:""
            // },
            {
                title: "视频",
                subtitle: "实物购买",
                url: ""
            }
        ],
        catIndex: 0,
        catArr: [{
                loading: false,
                title: '采购推荐',
                current_page: 0,
                pages: 1,
                data: [],
                url: "/home/supplier/product/index?limit=20",
                reqData: {
                    purchase: 1,
                    limit: 20
                }
            },
            {
                loading: false,
                title: '整点秒杀',
                current_page: 0,
                pages: 1,
                url: "/home/ump/seckill/product?limit=20",
                data: [],

            }
        ],
        time: {},
        special: [{
                title: "天天特价",
                url: '/home/supplier/product/index',
                data: {
                    type: 2
                }
            },
            // {
            // 	title:"秒杀专区",
            // 	url:'/home/ump/seckill/product',
            // 	data:{}
            // }
        ],
        specialIndex: 0,
        specialloading: false,
        specialList: [],
        seckillloading: false,
        seckillList: [],
        videoloading: false,
        videoList: [],

        nums: 1,
        addCart: false,
        pdc: {},
        sku: {},
        product_id: 0,
        product_name: "",
        carTitle: "",
        reqData: {},
        /**金刚区导航 2021.12.31 */
        navSwiperIndex: 0,
        totalMsg: 0,
        navListAll2: [{
                navList: [{
                    linkType: 'switchTab',
                    icon: "../../../assets/newIndex/tab1.png",
                    imgText: "体",
                    text: "联系客服",
                    url: 'kf'
                }, {
                    linkType: 'navigateTo',
                    icon: "../../../assets/newIndex/tab2.png",
                    imgText: "体",
                    text: "鲜花图册",
                    url: '/pages/album/album?state=1'
                }, {
                    linkType: 'navigateTo',
                    icon: "../../../assets/newIndex/tab3.png",
                    imgText: "体",
                    text: "常购清单",
                    url: '/pages/cls/often/List'
                }, {
                    linkType: 'navigateTo',
                    icon: "../../../assets/newIndex/tab4.png",
                    imgText: "体",
                    text: "包装费",
                    url: '/pages/article/Index?article_id=13'
                }, {
                    linkType: 'navigateTo',
                    icon: "../../../assets/newIndex/tab5.png",
                    imgText: "体",
                    text: "交易须知",
                    url: '/pages/article/help_center/help_center?cate_id=3&title=交易须知'
                }, {
                    linkType: 'navigateTo',
                    icon: "../../../assets/newIndex/tab6.png",
                    imgText: "体",
                    text: "同城鲜花",
                    url: '/pages/chat/cityGroup/index'
                }, {
                    linkType: 'navigateTo',
                    icon: "../../../assets/newIndex/tab7.png",
                    imgText: "体",
                    text: "当日账单",
                    url: '/pages/article/Index?article_id=24'
                }, {
                    linkType: 'navigateTo',
                    icon: "../../../assets/newIndex/tab8.png",
                    imgText: "体",
                    text: "运费查询",
                    url: '/pages/logistics/freight/freight'
                }, {
                    linkType: 'navigateTo',
                    icon: "../../../assets/newIndex/tab9.png",
                    imgText: "体",
                    text: "每日花价",
                    url: '/pages/cls/price/List'
                }, {
                    linkType: 'navigateTo',
                    icon: "../../../assets/newIndex/tab10.png",
                    imgText: "体",
                    text: "帮助中心",
                    url: '/pages/article/help_center/help_center?cate_id=4'
                }]
            },
            {
                navList: [{
                    linkType: 'navigateTo',
                    icon: "../../../assets/newIndex/tab11.png",
                    imgText: "体",
                    text: "求购",
                    url: '/pages/cls/qiugou_edit/edit'
                }]
            }
        ],

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        // this.getArticle()
        this.getAddress()
        this.getNav()
        this.getAreas()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        // if (this.data.whInfo) {
        //     getApp().globalData.warehouse = this.data.whInfo
        // }
        getApp().globalData.onMessage = this.onMessage;
        this.setData({
            totalMsg: getApp().globalData.msgCount
        })
        let Authorization = wx.getStorageSync('Authorization');
        if (getApp().globalData.SocketTask) { //如果未登陆或者已经链接socket  !Authorization || 
            return;
        }
        this.getUserInfo()
    },
    getUserInfo() {
        this.request({
            url: this.data.host + "/home/user/info"
        }, res => {
            // console.log("user/info",res.data);
            let userInfo = getApp().globalData.userInfo = res.data;
            getApp().connectSocket();
        });
    },
    onMessage(msg) {
        // console.log("聊天列表", msg)
        var that = this
        if (msg.type == "total_msg") {
            var totalMsg = msg.total_count
            that.setData({
                totalMsg: totalMsg
            })
        } else if (msg.type == "friend") {
            var totalMsg = this.data.totalMsg
            totalMsg = totalMsg + 1
            that.setData({
                totalMsg: totalMsg
            })
        }
    },
    getNav() {
        this.request({
            url: this.data.host + "/home/index/nav"
        }, res => {
            //navListAll2
            var list = []
            var navListAll2 = this.data.navListAll2
            if (navListAll2.length >= 3) return
            res.data.map((val, index) => {
                if (index < 9) {
                    list.push({
                        linkType: 'sort',
                        icon: this.get_thumb(val.icon),
                        text: val.title,
                        url: '/pages/region/goods/index',
                        id: val.link
                    })
                }
            })
            list.push({
                linkType: 'sort',
                icon: "../../../assets/newIndex/indexNav.png",
                text: "交易大厅",
                url: '/pages/region/goods/index'
            })

            navListAll2.unshift({
                navList: list
            })
            // console.log("navListAll2",navListAll2)
            this.setData({
                navListAll2: navListAll2
            })
        })
    },
    nav_click(e) {
        // console.log(e.currentTarget.dataset);
        let nav = e.currentTarget.dataset.nav
        if (nav.url == 'kf') {
            return this.service_click()
        }
        if (nav.linkType == 'func') {
            return this[nav.url]();
        }
        if (nav.linkType == 'toList') {
            return this.toList(e);
        }
        if (nav.linkType == 'switchTab') {
            return wx.switchTab({
                url: nav.url,

            })
        }
        if (nav.linkType == 'sort') {
            wx.setStorageSync('catId', nav.id)
            var warehouse = JSON.stringify(this.data.whInfo)
            wx.navigateTo({
                url: '/pages/region/goods/index?warehouse=' + warehouse,
            })
            return
            // return wx.switchTab({
            //     url: nav.url,

            // })
        }
        if(nav.text=="交易须知"){
            return wx.navigateTo({
                url: nav.url+"&wh_id="+this.data.whInfo.wh_id,
            })
        }
        if (nav.linkType == 'url') {
            return wx.navigateTo({
                url: nav.url,
            })
        }
        wx.navigateTo({
            url: nav.url + '?wh_id=' + this.data.wh_id,
        })
    },
    nav_swiper_change(e) {
        this.setData({
            navSwiperIndex: e.detail.current
        })
    },
    // 定位
    getAddress() {
        var that = this
        wx.getLocation({
            type: 'gcj02',
            success: function (res) {
                console.log("getLocation", res)
                var lat = res.latitude;
                var lng = res.longitude;
                that.setData({
                    lat: lat,
                    lng: lng
                })
                that.data.reqData.lat = lat
                that.data.reqData.lng = lng
                that.getWarehouse()
            },
            fail: err => {
                console.log("错误", err)
            }
        })
    },
    login_reload() {
        console.log("执行基类重载方法")
        this.getWarehouse()
    },
    changeAddress() {
        var {
            lat,
            lng,
            address,
        } = this.data
        var that = this
        var district = address.district || address.city || address.province
        this.setData({
            swiperCurrent: 0
        });
        wx.navigateTo({
            url: '/pages/region/regionList/index?lat=' + lat + "&lng=" + lng + "&area_code=" + address.province_code + "&district=" + district,
            events: {
                getRegion: function (data) {
                    console.log("切换地址", data)
                    that.data.reqData = data.data
                    // that.data.reqData.province_name = that.data.address.province
                    that.getWarehouse()
                },
                getLocation: function (data) {
                    that.data.reqData = {}
                    that.getAddress()
                }
            },
        })
    },
    //获取仓库信息
    getWarehouse() {
        var reqData = this.data.reqData
        this.request({
            url: this.data.host + '/home/getWhInfoByLocation',
            data: {
                // lat:25.038552,
                // lng:102.72221 
                ...reqData
            }
        }, res => {
            var data = res.data
            this.setData({
                address: data.address,
                whInfo: data.wh_info,
                glWhInfo: data.gl_wh_info,
                is_have_city: data.is_have_city,
                is_have_district: data.is_have_district
            })
            if (data.wh_info) {
                // getApp().globalData.warehouse = data.wh_info
                //有本地仓
                this.req_banner()
                this.getRate()
                this.getSales()

                this.getSpecialList(); //天天特价或秒杀
                this.getvideoList(); //视频商品
                this.getSeckillList(); //秒杀
                this.req_cat_data(this.data.catIndex) //采购推荐

                this.getTime()
            } else {
                //无本地仓查询文字
                this.getArticle()
            }

        })
    },
    //查询系统配置（秒杀时间）
    getTime() {
        this.request({
            url: this.data.host + '/home/index/config',
            data: {
                wh_id: this.data.whInfo.wh_id,
                type: 2
            }
        }, res => {
            this.setData({
                time: res.data
            })

        });
    },
    /**请求分类产品数据 */
    req_cat_data(catIndex) {
        let cat = this.data.catArr[catIndex];
        // if (cat.current_page == cat.pages) {
        //     return;
        // }
        cat.loading = true;
        this.setData({
            catArr: this.data.catArr
        })
        this.request({
            url: this.data.host + cat.url,
            data: {
                ...cat.reqData,
                //  limit:1,
                page: 1,
                wh_id: this.data.whInfo.wh_id,
                limit: 20,
            }
        }, res => {
            this.get_pdcs_ok(catIndex, res);
        }, null, res => {
            let cat = this.data.catArr[catIndex];
            cat.loading = false;
            this.setData({
                catArr: this.data.catArr
            })


        });
    },
    /**
     *  @param {int} catIndex 选中的分类索引
     * @param {*} res 后台返回的产品数据
     */
    get_pdcs_ok(catIndex, res) {
        let catArr = this.data.catArr;
        let cat = catArr[catIndex];
        cat.pages = res.pages;
        cat.current_page = res.current_page;
        // console.log("刷新底部产品列表", res);
        // console.log("选中的分类索引", catIndex);
        if (catIndex == 1) {
            res.data.map(val => {
                val.sku = val.total_num - val.sales
                val.thumb = this.get_thumb(val.product_img);
            })
        } else {
            res.data.map(val => {
                val.thumb = this.get_thumb(val.product_img);
                // console.log("val.thumb",val.thumb);
            });
        }

        res.current_page == 1 ? cat.data = res.data : cat.data = cat.data.concat(res.data);
        this.setData({
            catArr,
        });
        wx.stopPullDownRefresh({
            success: (res) => {},
        })
        // this.setData({
        //   pdcArr: res.data
        // })
    },
    //请求天天特价产品数据
    getSpecialList(index) {
        let special = this.data.special[this.data.specialIndex];
        this.request({
            url: this.data.host + special.url,
            data: {
                limit: 20,
                page: 1,
                wh_id: this.data.whInfo.wh_id,
                ...special.data
            }
        }, res => {
            // console.log("天天特价", res)
            var list = res.data
            if (this.data.specialIndex == 1) {
                list.map(val => {
                    val.sku = val.total_num - val.sales
                    val.thumb = this.get_thumb(val.product_img);
                })
            } else {
                list.map(val => {
                    val.thumb = this.get_thumb(val.product_img);
                })
            }

            this.setData({
                specialloading: false,
                specialList: list
            })
        });
    },
    //请求整点秒杀
    getSeckillList(index) {
        // let special = this.data.special[this.data.specialIndex];
        this.request({
            url: this.data.host + "/home/supplier/product/index",
            data: {
                limit: 20,
                page: 1,
                wh_id: this.data.whInfo.wh_id,
                is_seckill: 1
            }
        }, res => {
            // console.log("整点秒杀", res)
            var list = res.data
            list.map(val => {
                // val.sku = val.total_num - val.sales
                val.thumb = this.get_thumb(val.product_img);
            })

            this.setData({
                seckillloading: false,
                seckillList: list
            })
        });
    },
    //视频商品列表
    getvideoList(index) {
        // let special = this.data.special[this.data.specialIndex];
        this.request({
            url: this.data.host + "/home/supplier/product/index",
            data: {
                limit: 20,
                page: 1,
                wh_id: this.data.whInfo.wh_id,
                is_video: 1
            }
        }, res => {
            // console.log("整点秒杀", res)
            var list = res.data
            list.map(val => {
                // val.sku = val.total_num - val.sales
                val.thumb = this.get_thumb(val.product_img);
            })

            this.setData({
                videoloading: false,
                videoList: list
            })
        });
    },
    //获取商品涨跌
    getRate() {
        this.request({
            url: this.data.host + '/home/index/rateByCate',
            data: {
                wh_id: this.data.whInfo.wh_id
            },
            method: 'GET'
        }, res => {
            var list = res.data
            list.map(val => {
                if (val.change_rate > 0) {
                    val.state = 1
                } else {
                    val.state = 0
                }
            })
            this.setData({
                analysisList: list
            })

        });
    },
    //获取实时成交量
    getSales() {
        this.request({
            url: this.data.host + '/home/index/sales',
            data: {
                wh_id: this.data.whInfo.wh_id
            },
            method: 'GET'
        }, res => {

            this.setData({
                turnoverList: res.data.real_list,
                sales: res.data.sales
            })
        });
    },
    //获取文章
    getArticle() {
        this.request({
            url: this.data.host + '/home/article/detail?article_id=106'
        }, this.get_detail_ok);
    },
    get_detail_ok(res) {
        console.log("get_detail_ok", res);
        this.getConfig()
        this.setData({
            article_content: res.data.article_content.content.replace(/<img /ig, '<img width="100%" ')
        });
    },
    //配置信息
    getConfig() {
        this.request({
            url: this.data.host + '/home/whRecruitMsg'
        }, res => {
            this.setData({
                phone: res.data.tel
            })
        });
    },
    onPhone(e) {
        var phone =  e.currentTarget.dataset.item
        wx.makePhoneCall({
            phoneNumber: phone
        })
    },
    submit() {
        var {
            name,
            mobile,
            remark,
            reqData,
            addr,
            typeInfo
        } = this.data
        if (!name) {
            wx.showToast({
                title: '请输入您的姓名',
                icon: "none"
            })
            return;
        }
        if (!mobile) {
            wx.showToast({
                title: '请输入您的电话',
                icon: "none"
            })
            return;
        }
        if (!typeInfo.name) {
            wx.showToast({
                title: '请选择入驻类型',
                icon: "none"
            })
            return;
        }
        if (!addr) {
            wx.showToast({
                title: '请选择入驻地区',
                icon: "none"
            })
            return;
        }
        this.setData({
            showInfo: false
        })
        this.request({
            url: this.data.host + "/home/whRecruit",
            data: {
                name,
                mobile,
                remark,
                type:typeInfo.type,
                ...reqData
            },
            method: "POST",
            loadingTip: "提交中···"
        }, res => {})
    },
    /**
     * 请求轮播图
     */
    req_banner() {
        //请求轮播图
        this.request({
            url: this.data.host + '/home/index/banner?from=warehouse&wh_id=' + this.data.whInfo.wh_id
        }, res => {
            res.data.map(val => {
                val.thumb = this.get_thumb(val.photo, 'wide');
                val.color = val.color ? val.color : '#2EB356'
            })
            this.setData({
                bannerArr: res.data,

            })
        })
    },
    onSwiperChange(e) {
        this.data.headBgTransition || this.setData({
            headBgTransition: true
        });
        const {
            current
        } = e.detail;
        this.setData({
            swiperCurrent: current
        });
    },
    changeActive(e) {
        var index = e.currentTarget.dataset.index
        // if(index==3){
        //     wx.showToast({
        //       title: '开发中···',
        //       icon:"none"
        //     })
        //     return;
        // }
        this.setData({
            activeIndex: index
        })
    },
    //切换本地仓和关联仓
    changeWh() {
        var warehouse = JSON.stringify(this.data.glWhInfo)
        wx.navigateTo({
            url: '/pages/region/goods/index?warehouse=' + warehouse,
        })
        // var {
        //     whInfo,
        //     glWhInfo
        // } = this.data
        // this.setData({
        //     whInfo: glWhInfo,
        //     glWhInfo: whInfo,
        // })
        // // getApp().globalData.warehouse = this.data.whInfo
        // wx.showToast({
        //   title: '已经切换仓库，请到本地交易大厅下单',
        //   icon:"none"
        // })
        // this.req_banner()
        // this.getRate()
        // this.getSales()

        // this.getSpecialList(); //天天特价或秒杀
        // this.getvideoList(); //视频商品
        // this.getSeckillList(); //秒杀
        // this.req_cat_data(this.data.catIndex) //采购推荐

        // this.getTime()
    },
    //跳转分仓拼单
    clickToCollate() {
        if (this.data.whInfo.wh_id == 1) {
            wx.showToast({
                title: '请到昆明仓下单！',
                icon: "none"
            })
            return;
        }
        wx.navigateTo({
            url: '/pages/collate/collate?warehouse=' + JSON.stringify(this.data.whInfo),
        })
    },
    /**鲜花预售 */
    presell_click() {
        wx.navigateTo({
            url: '/pages/preSaleList/preSaleList?wh_id=' + this.data.whInfo.wh_id,
        })
        // wx.navigateTo({
        // 	url: '/pages/cls/list/BaseList?reqUrl=/home/ump/presell/product&preUrl=/home/ump/presell/preinfo&title=预售专区',
        // })
    },
    // 次日达
    toNextDay() {
        wx.navigateTo({
            url: '/pages/cls/list/BaseList?reqUrl=/home/supplier/product/index&preUrl=/home/ump/seckill/preinfo&title=次日达' + "&wh_id=" + this.data.whInfo.wh_id,
        })
    },
    //跨区域
    toRegion() {
        wx.navigateTo({
            url: '/pages/cls/list/BaseList?reqUrl=/home/supplier/product/index&preUrl=/home/ump/seckill/preinfo&title=跨区域'+ "&wh_id=" + this.data.whInfo.wh_id,
        })
    },
    /**捡漏 */
    live_click() {
        var title = "捡漏"
        if(this.data.whInfo.wh_id==1){
            title="市场捡漏"
        }
        wx.navigateTo({
            url: '/pages/cls/list/BaseList?reqUrl=/home/supplier/product/index&preUrl=/home/ump/seckill/preinfo&title=' +
                title + "&wh_id=" + this.data.whInfo.wh_id,
        })
    },
    tolink(e) {
        let link = e.currentTarget.dataset.link
        if (link) {
            wx.navigateTo({
                url: link,
            })
        }
    },
    /**确认搜索内容 */
    search_click(e) {
        // console.log("search_click", e);
        wx.navigateTo({
            url: '/pages/cls/pdcList/Index?so=' + e.detail + "&wh_id=" + this.data.whInfo.wh_id
        })

    },
    toAnalysis(e) {
        console.log("数据分析", e)
        var cate_id = ""
        if (e.currentTarget.dataset.item) {
            cate_id = e.currentTarget.dataset.item.cate_id
        }
        wx.navigateTo({
            // url: "/pages/cls/market/Echart" ,
            url: "/pages/cls/index/analysis/analysis?wh_id=" + this.data.whInfo.wh_id + "&cate_id=" + cate_id,
        })
    },
    /**
     * 添加购物车按钮点击事件
     * @param {*} param0 
     */
    add_cart_click(e) {
        let pdc = e.detail;
        // console.log("秒杀", pdc)
        this.setData({
            nums: 1,
            addCart: true,
            pdc: pdc,
            sku: pdc.sku,
            product_id: pdc.pid,
            product_name: pdc.product_name,
            carTitle: e.currentTarget.dataset.titlt

        });
    },
    add_cart_click2(e) {
        let pdc = e.detail;
        this.setData({
            nums: 1,
            addCart: true,
            pdc: pdc,
            sku: pdc.sku,
            product_id: pdc.pid,
            product_name: pdc.product_name,
            carTitle: "整点秒杀"

        });
    },
    onCloseCart() {
        this.setData({
            addCart: false
        })
    },
    /**
     * 添加产品到购物车
     */
    add_cart() {
        let data = {
            pid: this.data.product_id,
            nums: this.data.nums,
        }
        let pdc = this.data.pdc
        if (pdc.is_seckill == 1 && this.data.carTitle == "整点秒杀") { //秒杀
            data.from = "seckill"
        } else {
            data.from = "flower"
        }

        this.request({
            url: this.data.host + '/home/cart/addToCart',
            data: data,
            method: 'post'
        }, this.add_cart_ok);

    },
    //立即购买
    buy_good() {
        console.log("立即购买", this.data.pdc)
        let data = {
            pid: this.data.product_id,
            nums: this.data.nums,
            wh_id: this.data.whInfo.wh_id
        }
        let pdc = this.data.pdc
        if (pdc.is_seckill == 1 && this.data.carTitle == "整点秒杀") { //秒杀
            data.from = "seckill"
        } else {
            data.from = "flower"
        }

        this.request({
            url: this.data.host + '/home/flower/preInfo',
            data: data,
            method: 'get'
        }, res => {
            this.setData({
                addCart: false
            })
            res.data.cashier_decca = this.get_thumb(res.cashier_decca, 'wide');
            let that = this;
            wx.navigateTo({
                // url: '/pages/order_confirm/order_confirm',
                url: '/pages/neworder_confirm/order_confirm',
                success: function (obj) {
                    // 通过eventChannel向被打开页面传送数据

                    obj.eventChannel.emit('orderData', {
                        wh_id: that.data.whInfo.wh_id,
                        // index: that.data.areaData[that.data.tabIndex].index,
                        data: res.data,
                        m_addr: res.m_addr,
                        activeCar: data.from,
                        wuliu: res.data.freight_list,
                        specialList: res.data.extra_list,
                        pack_list: res.data.pack_list,
                        buyType: 1, //1立即购买0购物车
                        order_pei_type: res.order_pei_type,
                        orderWarehouse: res.warehouse
                    })
                }
            })
        });
    },

    /**
     * 添加购物车结果处理
     * @param {*} res  后台返回的数据
     */
    add_cart_ok(res) {
        // console.log("add_cart_ok",res);
        // this.setData({nums:1})
        this.setData({
            addCart: false
        })
        wx.showToast({
            title: res.msg,
            icon: 'success'
        })
    },
    add_preinfo_ok(res) {
        // console.log('add_preinfo_ok', res);
        wx.navigateTo({
            url: '/pages/preSaleList/preinfo/Order?noShowNum=1',
            success: function (obj) {
                // 通过eventChannel向被打开页面传送数据
                obj.eventChannel.emit('orderData', {
                    data: res.data,
                    m_addr: res.data.m_addr
                })
            }
        })
    },
    nums_change(e) {
        // this.data.nums = e.detail;
        this.setData({
            nums: e.detail
        })
        // console.log("nums_change", e)
    },
    //跳转本地仓交易大厅
    toNativeGoods() {
        var warehouse = JSON.stringify(this.data.whInfo)
        wx.navigateTo({
            url: '/pages/region/goods/index?warehouse=' + warehouse,
        })
    },
    //招募城市仓
    addCityGroup() {

        wx.navigateTo({
            url: '/pages/region/whInfo/index',
        })
    },

    /**
     * 点击客服按钮
     */
    service_click() {
        // console.log("socket连接状态", getApp().globalData.showSocket)
        var that = this
        if (!getApp().globalData.showSocket) {
            wx.showModal({
                title: '客服系统已断开',
                content: '请确定是否重连',
                success(res) {
                    if (res.confirm) {
                        // console.log('用户点击确定')
                        getApp().globalData.number = 0
                        getApp().globalData.againSocket = 1
                        // getApp().connectSocket();
                        that.getUserInfo()

                    } else if (res.cancel) {
                        // console.log('用户点击取消')
                    }
                }
            })
            return;
        }
        // console.log("聊天次数", getApp().globalData.number)
        if (getApp().globalData.number >= 3) {
            wx.showToast({
                title: '聊天服务异常，请重启小程序或者联系客服',
                icon: 'none',
                duration: 2000
            })
            return;
        }
        wx.navigateTo({
            url: '/pages/chat/chatList/chatList?wh_id='+this.data.whInfo.wh_id
        })
    },
    getAreas() {
        let that = this
        wx.request({
            url: that.data.host + "/uploads/gaode.json",
            header: {},
            success(res) {
                let result = res.data.districts[0].districts
                let arrs = [{
                    values: result
                }, {
                    values: result[0].districts,
                    defaultIndex: 0,
                }, {
                    values: result[0].districts[0].districts,
                    defaultIndex: 0,
                }]
                console.log("arrs", arrs)
                that.setData({
                    addrs: arrs
                })
            }
        })
    },
    // 省市区变动
    onAreaChange(e) {
        const {
            picker,
            value,
            index
        } = e.detail;
        if (index === 0) {
            // 修改省
            picker.setColumnValues(1, value[0].districts);
            picker.setColumnValues(2, value[0].districts[0].districts);
        } else if (index === 1) {
            // 修改市
            picker.setColumnValues(2, value[1].districts);
        }
    },
    // 确认选择省市区
    onAreaConfirm(e) {
        let areaArr = e.detail.value;
        let reqData = this.data.reqData;
        //初始化省市县数据
        reqData.province = areaArr[0].name;
        reqData.province_code = areaArr[0].adcode;
        reqData.city = areaArr[1].name;
        reqData.city_code = areaArr[1].adcode;
        reqData.district = areaArr[2].name;
        reqData.district_code = areaArr[2].adcode;
        this.setData({
            addr: reqData.province + reqData.city + reqData.district,
            showArea: false,

        })
    },
    selectType(e) {
        this.setData({
            typeInfo:e.detail,
            showtype:false

        })
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})